<template>
	<view class="my-userinfo-container">
		<!-- 头像和昵称区域 -->
    <view class="top-box">
      <image :src="userinfo.headImage" class="avater"></image>
      <view class="nickname">{{userinfo.wxName}}</view>
    </view>
    
    <!-- 面板区 -->
    <view class="panel-list">
      <!-- 第一个面板 -->
      <view class="panel">
        <view class="panel-body">
          <view class="panel-item">
            常用功能
          </view>
        </view>
      </view>

      <!-- 第三个面版 -->
      <view class="panel">
        <view class="panel-list-item" @click="gotoAn">
          <text>问答日志</text>
            <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image>
        </view>
        <hr/>
        <view class="panel-list-item" @click="selectAI">
          <text>绘画日志</text>
            <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image>
        </view>
       <hr/>
        <view class="panel-list-item">
          <text>意见反馈</text>
          <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image> 
        </view>
         <hr/>
        <view class="panel-list-item">
          <text>联系客服</text>
            <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image>
        </view>
         <hr/>
        <view class="panel-list-item">
          <text>帮助中心</text>
            <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image>
        </view>
         <hr/>
        <view class="panel-list-item" @click="logout">
          <text>退出登录</text>
            <image src="../../static/arrowright.png" style="width: 15px;height: 15px;"></image>
        </view>
      </view>
    </view>
	</view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
   import request from "../../request/request.js";
	export default {
		data() {
			return {
			};
		},
    computed:{
      ...mapState('m_user',['userinfo'])
    },
    methods:{
      ...mapMutations('m_user',['updateUserInfo']),
      async logout(){
        const [err,succ] = await uni.showModal({
          title:'提示',
          content:'确认退出登录吗?'
        }).catch(err=>err)
        
        if(succ && succ.confirm){
          this.updateUserInfo('');
		  request('', '/User/logout', 'GET', null, {}).then(res => {
		  	console.log("首次请求返回结果",res)
		  	if (res.code == 200) {
				uni.setStorageSync("accessToken","");
				uni.setStorageSync("refreshToken","");
		  	// this.updateUserInfo(res.data);
		  	} else{
		  		uni.showToast({
		  			title: '请求错误',
		  			icon: 'error',
		  			duration: 2000
		  		});
		  	}
		  	uni.hideLoading();
		  })	
        }
      },
      gotoAn(){
        uni.navigateTo({
            url: '/pages/main/answerslog/answerslog', // 跳转到名为secondPage的页面
            success: function(res) {
                console.log('跳转成功')
            },
            fail: function(err) {
                console.log('跳转失败：' + err)
            }
        })
      },
	  selectAI(){
		  let data={
			  userId:this.userinfo.id
		  }
		  request('', '/painting/getById', 'GET', data, {}).then(res => {
		  	console.log("首次请求返回结果",res)
		  	if (res.code == 200) {
		  				uni.setStorageSync("accessToken","");
		  				uni.setStorageSync("refreshToken","");
		  	
        uni.navigateTo({
            url: '/pages/main/huihualog/huihualog', // 跳转到名为secondPage的页面
            success: function(res) {
                console.log('跳转成功')
            },
            fail: function(err) {
                console.log('跳转失败：' + err)
            }
        })
		  	} else{
		  		uni.showToast({
		  			title: '请求错误',
		  			icon: 'error',
		  			duration: 2000
		  		});
		  	}
		  	uni.hideLoading();
		  })
	  }
    }
	}
</script>

<style lang="scss">

  
  
.my-userinfo-container{
  height: 100%;
  background-color: #f4f4f4;
  .top-box{
    height: 400rpx;
    background-color: #4169E1;
    display: flex;
    align-items: center;
    flex-direction: column; 
    .avater{
      width: 90px;
      height: 90px;
      border-radius: 45px;
      border: 2px solid #fff;
      box-shadow: 0 1px 5px black;
    }
    .nickname{
      font-size: 16px;
      color: #fff;
      font-weight: bold;
      margin-top: 10px;
    }
  }
}

.panel-list{
  padding: 0 10px;
  position: relative;
  top: -10px;
  .panel{
    background-color: white;
    border-radius: 3px;
    margin-bottom: 8px ;
    .panel-title{
      line-height: 45px;
      padding-left: 10px;
      font-size: 15px;
      border-bottom: 1px solid #f4f4f4;
    }
    
    .panel-body{
      display: flex;
      justify-content: space-around;
      .panel-item{
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        padding: 10px 0;
        font-size: 13px;
        
        .icon{
          width: 35px;
          height: 35px;
        }
      }
    }
  }
}

.panel-list-item{
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  padding: 0 10px;
  line-height: 45px;
}
</style>
